﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Dal.Sale
{
    public class Supplier
    {
        protected string 供货单位;
        protected string 地址;
        protected string 电话;
        protected string 开户银行;
        protected string 账号;
        protected string 邮政编码;
        protected string 税号;
        protected string 详细供货单位;

        public Supplier getSupplier(int supplierID,int 类别){
            Supplier obj = new Supplier();
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            if (类别 == 0)
            {
                Cmd.CommandText = "select 名称,地址,电话,开户银行,账号,邮政编码,税号,详细名称 from 原料供货单位  where ID=" + supplierID;
            }
            if (类别 == 1)
            {
                Cmd.CommandText = "select 名称,地址,电话,开户银行,账号,邮政编码,税号,详细名称 from 材料供货单位  where ID=" + supplierID;
            }
            SqlDataReader Reader = Cmd.ExecuteReader();
            if (Reader.Read())
            {
                if (Reader.IsDBNull(0))
                {
                    obj.供货单位 ="";
                }else{
                    obj.供货单位 = Reader.GetString(0);
                }
                if (Reader.IsDBNull(1))
                {
                    obj.地址 = "";
                }
                else
                {
                    obj.地址 = Reader.GetString(1);
                }
                if (Reader.IsDBNull(2))
                {
                    obj.电话 = "";
                }
                else
                {
                    obj.电话 = Reader.GetString(2);
                }
                if (Reader.IsDBNull(3))
                {
                    obj.开户银行 = "";
                }
                else
                {
                    obj.开户银行 = Reader.GetString(3);
                }
                if (Reader.IsDBNull(4))
                {
                    obj.账号 = "";
                }
                else
                {
                    obj.账号 = Reader.GetString(4);
                }
                if (Reader.IsDBNull(5))
                {
                    obj.邮政编码 = ""; 
                }
                else
                {
                    obj.邮政编码 = Reader.GetString(5);
                }
                if (Reader.IsDBNull(6))
                {
                    obj.税号 = "";
                }
                else
                {
                    obj.税号 = Reader.GetString(6);
                }
                if (Reader.IsDBNull(7))
                {
                    obj.详细供货单位 = "";
                }
                else
                {
                    obj.详细供货单位 = Reader.GetString(7);
                }
            }
            Reader.Close();
            Conn.Close();
            Reader.Dispose();
            Cmd.Dispose();
            return obj;
            
        }
        public string get供货单位()
        {
            return 供货单位;
        }
        public string get地址()
        {
            return 地址;
        }
        public string get电话()
        {
            return 电话;
        }
        public string get开户银行()
        {
            return 开户银行;
        }
        public string get账号()
        {
            return 账号;
        }
        public string get邮政编码()
        {
            return 邮政编码;
        }
        public string get税号()
        {
            return 税号;
        }
        public string get详细供货单位()
        {
            return 详细供货单位;
        }
    }
}
